package com.study2.DouDiZhu;

import java.util.ArrayList;
import java.util.Collections;

public class PokerGame {
    private static ArrayList<String> pokerList = new ArrayList<String>();
    
    // 初始化牌库
    static {
        String[] color = {"♥", "♠", "♣", "♦"};
        String[] number = {"3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2"};
        
        for (String c : color) {
            for (String n : number) {
                pokerList.add(c + n);
            }
        }
        pokerList.add("小王");
        pokerList.add("大王");
    }
    
    public PokerGame() {
        System.out.println("初始化牌库");
        System.out.println(pokerList);
        
        // 洗牌
        System.out.println("洗牌");
        Collections.shuffle(pokerList);
        System.out.println(pokerList);
        
        // 发牌
        ArrayList<String> load = new ArrayList<String>();
        ArrayList<String> player1 = new ArrayList<String>();
        ArrayList<String> player2 = new ArrayList<String>();
        ArrayList<String> player3 = new ArrayList<String>();
        
        // 遍历牌盒子
        for (int i = 0; i < pokerList.size(); i++) {
            String poker = pokerList.get(i);
            // 前三张 发给地主
            if (i < 3) {
                load.add(poker);
                continue;
            }
            // 发给其他三人
            switch (i % 3) {
                case 0:
                    player1.add(poker);
                    break;
                case 1:
                    player2.add(poker);
                    break;
                case 2:
                    player3.add(poker);
                    break;
            }
        }
        lookPoker("地主牌", load);
        lookPoker("玩家1", player1);
        lookPoker("玩家2", player2);
        lookPoker("玩家3", player3);
    }
    
    public void lookPoker(String name, ArrayList<String> list){
        System.out.println(name);
        System.out.println(list);
    }
}
